﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Book
{
    public partial class Form4_1 : Form
    {
        public Form4_1()
        {
            InitializeComponent();
        }

        private void Form4_1_Load(object sender, EventArgs e)
        {
            label10.Text = string.Format("读者编号：{0}", UserHelper.UserName);
            timer1.Start();
            OleDbConnection DBconnect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
            DBconnect.Open();
            string SqlCmd = "select * from reader where 读者编号='" + UserHelper.UserName + "'";
            OleDbDataAdapter dbDataAdapter = new OleDbDataAdapter(SqlCmd, DBconnect); //创建适配对象             
            DataTable dtable = new DataTable(); //新建表对象             
            dbDataAdapter.Fill(dtable); //用适配对象填充表对象            
            if (dtable.Rows.Count > 0)
            {
                foreach (DataRow item in dtable.Rows)
                {
                    textBox1.Text = item[1].ToString();
                    textBox2.Text = item[2].ToString();
                    textBox3.Text = item[3].ToString();
                    textBox4.Text = item[4].ToString();
                    textBox5.Text = item[5].ToString();
                    textBox6.Text = item[6].ToString();
                    textBox7.Text = item[7].ToString();

                }
            }
            else { MessageBox.Show("Null Value!"); }
        }

        private void 查看个人借阅ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_2 form4_2 = new Form4_2();
            form4_2.Show();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
            this.Close();
        }

        private void 修改个人信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_3 form4_3 = new Form4_3();
            form4_3.Show();
        }

        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_4 form4_4 = new Form4_4();
            form4_4.Show();
        }

        private void 查看个人信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_1 form4_1 = new Form4_1();
            form4_1.Show();
        }

        private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定注销此用户吗？", "提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                OleDbConnection DBconnect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
                DBconnect.Open();
                string sql = string.Format("delete from reader where 读者编号='{0}'", UserHelper.UserName);             //删除执行             
                OleDbCommand oleDbCommand = new OleDbCommand(sql, DBconnect);
                int i = oleDbCommand.ExecuteNonQuery();
                MessageBox.Show("注销成功！");
                Form1 form1 = new Form1();
                form1.Show();
                this.Close();
            }
            else
            {
                Form3 form3 = new Form3();
                form3.Show();
                this.Close();
            }
        }

        private void 查看图书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_5 form4_5 = new Form4_5();
            form4_5.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label9.Text = DateTime.Now.ToString(); 
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }
        }

         
}
